package com.sq.partner.manager.dao.impl;


import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.sq.partner.manager.dao.IPushInfoManagerDao;
import com.sq.partner.manager.mybatis.model.CoreDept;
import com.sq.partner.manager.mybatis.model.TGatewayInvoice;
import com.sq.partner.manager.util.LogUtil;
import com.sq.partner.manager.util.Page;
@Repository
public class PushInfoManagerDaoImpl extends BaseDaoImpl implements IPushInfoManagerDao {
	
	private static Logger logger = LogUtil.getLog(PushInfoManagerDaoImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<String> queryUserDept(String userId) throws Exception {
		return (List<String>) this.queryList("queryUserDeptByUserId", userId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CoreDept> queryDeptList(List<String>  deptStr) throws Exception {
		return this.queryList("queryCoreDeptByUserDept", deptStr);
	}

	/**
	 * 查询主页列表
	 */
	@Override
    public Page queryInviocePageByCriteria(Page page) throws Exception {     
        Map<String,Object> map = (Map<String, Object>) page.getType(); 
        page.setTotal((Integer)this.query("queryInvioceCountByMap", map));
        List<TGatewayInvoice> list = queryList("queryInviocePageByMap", map);
        page.setData(list); 
        return page;
    }

	
	@Override
	public boolean editInvioceGroup(TGatewayInvoice tGatewayInvoice)throws Exception {
		return this.update("updateInvioceNotNull", tGatewayInvoice);
	}

	@Override
	public List<Map<String, Object>> beforePushInvioce(Map<String, Object> map)throws SQLException {
		return this.queryList("beforePushInvioce", map);
	}
	
	@Override
	public List<Map<String, Object>> queryInvioceByID(Map<String, Object> map)throws SQLException {
		return  this.queryList("queryInvioceByIDs", map);
	}


	@Override
	public Map<String, String> queryIsPushInvioceBypartnerNo(String partnerNo)throws Exception {
		
		return (Map<String, String>) this.query("queryIsPushInvioceBypartnerNo", partnerNo);
	}

	@Override
	public void rePushByPol(String polNo) throws Exception {
		this.update("rePushByPol",polNo);
	}

	@Override
	public void rePushByPolList(List<String> polList) throws Exception {
		try{
			this.batchUpdate("rePushByPolList",polList);
		}catch (Exception e){
			throw new Exception(e);
		}
	}

	@Override
	public String selectInvoiceStatusByPol(String polNo) throws SQLException {
		return (String) this.query("selectInvoiceStatusByPol",polNo);
	}

	@Override
	public Page queryNocarInviocePageByCriteria(Page page) throws Exception {
		Map<String,Object> map = (Map<String, Object>) page.getType();
		page.setTotal((Integer)this.query("queryNocarInvioceCountByMap", map));
		List<TGatewayInvoice> list = queryList("queryNocarInviocePageByMap", map);
		page.setData(list);
		return page;
	}

}
